
Partial Class Modules_Questionnaires_InstrumentManager
    Inherits baseWebPage

    Protected Sub butClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles butClear.Click
        ddlFieldToSearch.SelectedIndex = 0
        txtStringToSearch.Text = String.Empty
    End Sub

    Protected Sub butInsert_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
        Dim ctbName As TextBox
        Dim txtInstrumentId As TextBox
        If gvInstruments.Rows.Count = 0 Then
            ctbName = gvInstruments.Controls(0).Controls(0).FindControl("ctbName")
            txtInstrumentId = gvInstruments.Controls(0).Controls(0).FindControl("txtInstrumentId")
        Else
            ctbName = gvInstruments.FooterRow.FindControl("ctbName")
            txtInstrumentId = gvInstruments.FooterRow.FindControl("txtInstrumentId")
            gvInstruments.ShowFooter = False
        End If
        DotNetPM.Business.Questionnaire.InstrumentODS.CreateInstrument(txtInstrumentId.Text, ctbName.Text)
        gvInstruments.DataBind()
        lbutNew.Enabled = True
    End Sub

    Protected Sub butCancel_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
        If gvInstruments.Rows.Count = 0 Then
            Dim trEmpty As HtmlTableRow _
            = gvInstruments.Controls(0).Controls(0).FindControl("trEmpty")
            trEmpty.Visible = False
            Dim trEmptyMessage As HtmlTableRow _
            = gvInstruments.Controls(0).Controls(0).FindControl("trEmptyMessage")
            trEmptyMessage.Visible = True
        Else
            gvInstruments.ShowFooter = False
        End If
        lbutNew.Enabled = True
    End Sub

    Protected Sub lbutNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbutNew.Click
        If gvInstruments.Rows.Count = 0 Then
            Dim trEmpty As HtmlTableRow _
            = gvInstruments.Controls(0).Controls(0).FindControl("trEmpty")
            trEmpty.Visible = True
            Dim trEmptyMessage As HtmlTableRow _
            = gvInstruments.Controls(0).Controls(0).FindControl("trEmptyMessage")
            trEmptyMessage.Visible = False
        Else
            gvInstruments.ShowFooter = True
        End If
        gvInstruments.EditIndex = -1
        lbutNew.Enabled = False
    End Sub


    Protected Sub gvInstruments_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvInstruments.RowCommand
        Select Case e.CommandName
            Case "ShowDetail"
                ' Convert the row index stored in the CommandArgument
                ' property to an Integer.
                Dim index As Integer = Convert.ToInt32(e.CommandArgument) _
                    - gvInstruments.PageIndex * gvInstruments.PageSize
                ' Retrieve the row that contains the button clicked 
                ' by the user from the Rows collection.
                Dim row As GridViewRow = gvInstruments.Rows(index)
                Session("questionnaire_instrumentId") = _
                CType(row.Cells(0).FindControl("lblInstrumentId"), Label).Text
                SetPreviousPage()
                Response.Redirect("InstrumentDetail.aspx")
                'Response.Write("Instrument Id : " & CType(row.Cells(0).FindControl("lblInstrumentId"), Label).Text)
            Case "LockInstrument"
                Dim index As Integer = Convert.ToInt32(e.CommandArgument) _
                    - gvInstruments.PageIndex * gvInstruments.PageSize
                Dim row As GridViewRow = gvInstruments.Rows(index)
                DotNetPM.Business.Questionnaire.InstrumentODS.LockInstrument( _
                    CType(row.Cells(0).FindControl("lblInstrumentId"), Label).Text)
                gvInstruments.DataBind()
        End Select
        gvInstruments.ShowFooter = False
        lbutNew.Enabled = True
    End Sub

    Protected Sub iButQuestion_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles iButQuestion.Click
        Response.Redirect("QuestionManager.aspx")
    End Sub

    Protected Sub iButQuestionnaire_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles iButQuestionnaire.Click
        Response.Redirect("QuestionnaireManager.aspx")
    End Sub
End Class
